﻿Ext.require([
    'Ext.tree.*',
    'Ext.data.*',
    'Ext.layout.container.HBox',
    'Ext.window.MessageBox'
]);

Ext.define('treeModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name'},
        {name: 'text', mapping: 'name'},
        {name: 'code'},
        {name: 'id'},
   //     {name:'checked'},
        {name: 'url'},
        {name: 'leaf'}
    ]
});

var unitStore = Ext.create('Ext.data.Store', {
    fields: ['abbr', 'name'],
    data : [
            {"abbr":"1", "name":"元"},
            {"abbr":"10000", "name":"万元"},
            {"abbr":"100000000", "name":"亿元"}
    ]
});

function EleStoreEnum(param){
	//code#value+code1#value1
	 var json_store = new Array();
	 var keyValues = param.split("+");
	 for (var i = 0; i < keyValues.length; i++){
		 var keyValue = keyValues[i];
		 var key_value = keyValue.split("#");
		 var key = key_value[0];
		 var value = key_value[1];
		 json_store.push({id: key, code: key, name: value});
	 }
	var enumStore = Ext.create('Ext.data.Store', {
		fields: ['code', 'name'],
	    data :json_store
	});
	return enumStore;
}
  
function getQueryStrore(cId, params) {
    var extraParams = {};
    if (typeof params == 'object') {
        extraParams = params;
    }
    for(var key in q_condition){
    	extraParams[key] = q_condition[key];
        if(q_condition["condition"] && key=="condition"){
            extraParams["condition"] = decodeURIComponent(q_condition["condition"]);
        }
    }
    var debtStoreDB = new Ext.data.Store({
        autoLoad: true,
        fields: ['code', 'name'],
//        sorters: [{
//            property: 'code',
//            direction: 'asc'
//        }],
        proxy: {
            type: 'ajax',
            url: '/sys-report/getQueryStrore?cId=' + cId,
            extraParams: extraParams,
            reader: {
                type: 'json',
                root: 'list'
            }
        }
    });
    return debtStoreDB;
}

/*下拉树形式，从后台数据库获取数据*/
function DebtQueryTreeStore(cId, params, isMul) {
    var extraParams = {};
    if (typeof params == 'object') {
        extraParams = params;
    }
    for(var key in q_condition){
    	extraParams[key] = q_condition[key];
    	if(q_condition["condition"] && key=="condition"){
            extraParams["condition"] = decodeURIComponent(q_condition["condition"]);
        }
    }
    var debtTreeStoreDB;
    if(isMul == 0){
    	debtTreeStoreDB = Ext.create('Ext.data.TreeStore', {
            model: 'treeModel',
            proxy: {
                type: 'ajax',
                method: 'POST',
                url: '/sys-report/getQueryTree?cId=' + cId,
                extraParams: extraParams,
                reader: {
                    type: 'json'
                }
            },
            root: {name: '全部'},
            autoLoad: true
        });
    }else{
    	debtTreeStoreDB = Ext.create('Ext.data.TreeStore', {
            model: 'treeModel',
            proxy: {
                type: 'ajax',
                method: 'POST',
                url: '/sys-report/getQueryTree?cId=' + cId,
                extraParams: extraParams,
                reader: {
                    type: 'json'
                }
            },
            root: {name: '全部',checked:false},
            autoLoad: true
        });
    }
    
    return debtTreeStoreDB;
}

function showwindows(url){
    Ext.create('Ext.window.Window', {
        width: 750, // 窗口宽度
        height: 400, // 窗口高度
        layout: 'fit',
        maximizable: true,
        items:[{
	    	 html:'<iframe id = "iframe_data" frameborder="0" width=100% height=100% src="'+url+'" />'
	    }]
    }).show();

}

/**
 * 选择父页面中菜单点击
 * 
 * @param menuId
 */
function menuOnClick(title, url) {
    try {
        if (typeof window.parent.addTab!= 'undefined') {
            window.parent.addTab(GUID.createGUID(),title, url);
        } else if (typeof window.parent.parent.addTab!= 'undefined') {
            window.parent.parent.addTab(GUID.createGUID(),title ,url);
        }else{
            //  window.open(url, '_blank');
    	    // urlSplit(url);
			window.open(url);
        }
    }catch(e) {
        window.open(url);
    }
}
